package com.river.springbootdemo.thinkingjava.containers;

import lombok.ToString;

import java.util.Arrays;

@ToString
public class TestParam {

    //元素的数量
    public final int size;

    //迭代的次数
    public final int loops;

    public TestParam(int size, int loops) {
        this.size = size;
        this.loops = loops;
    }

    //create an array of testParam from a varargs sequence
    //默认每两个参数为一组，生成一个TestParam ,第一个为size,第二个为loops
    public static TestParam[] array(int... values) {
        int size = values.length / 2;
        TestParam[] result = new TestParam[size];
        int n = 0;
        for (int i = 0; i < size; i++) {
            result[i] = new TestParam(values[n++], values[n++]);
        }
        return result;
    }

    public static void main(String[] args) {
        String[] strings={"6", "7", "8", "9", "10","11"};
        TestParam[] array = array(strings);
        System.out.println(Arrays.asList(array).toString());
    }

    //covert a String array to a TestParam array
    public static TestParam[] array(String[] values) {
        int[] vals = new int[values.length];
        for (int i = 0; i < vals.length; i++) {
            vals[i] = Integer.decode(values[i]);
        }
        return array(vals);
    }
}
